﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace DotNet.WebUI.ADO
{
    /// <summary>
    /// UsersAdd 的摘要说明
    /// </summary>
    public class UsersAdd : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");

            string _LoginID = context.Request["LoginID"].ToString();
            string _Name = context.Request["Name"].ToString();
            string _Depict = context.Request["Depict"].ToString();

            setUsers(_LoginID, _Name, _Depict);
        }

        public int setUsers(string LoginID, string Name, string Depict)
        {
            string _Sql = @"INSERT INTO Users (LoginID, Name, Pwd, Depict)
                VALUES('{0}', '{1}', '{2}', '{3}')";
            _Sql = string.Format(_Sql, LoginID, Name, "123456", Depict);

            SqlConnection objConn = new SqlConnection();
            objConn.ConnectionString = "server=LocalHost;Database=Demo;User ID=soft;password=123456;";
            objConn.Open();

            SqlCommand objCmd = new SqlCommand();
            objCmd.Connection = objConn;
            objCmd.CommandText = _Sql;

            return objCmd.ExecuteNonQuery();
        }
        
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}